package com.black.web.controller.find;

import com.black.app.domain.find.AppFindZhangzhishi;
import com.black.app.domain.find.AppFindZhangzhishiTitle;
import com.black.app.domain.req.find.add.Zhangzhishiaddreq;
import com.black.app.domain.req.find.edit.ZhangzhishiEssayEidtreq;
import com.black.app.domain.req.find.query.AppFIndZhangzhishititlereq;
import com.black.app.domain.req.find.query.AppFindZhangzhishiessayreq;
import com.black.app.domain.resp.find.FindTreeResp;
import com.black.app.domain.resp.find.FindZhangzhishiresp;
import com.black.app.service.find.AppFindZhangzhishiService;
import com.black.app.service.find.AppFindZhangzhishiTitleService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "App--find-涨知识")
@RestController
@RequestMapping(value = "/admin/find")

public class AdminFindZhangzhishiController extends BaseController {
    @Autowired
    private AppFindZhangzhishiService appFindZhangzhishiService;

    @Autowired
    private AppFindZhangzhishiTitleService appFindZhangzhishiTitleService;

    //    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "分页查询")
    @GetMapping(value = "/essay")
    public R<PageInfo<AppFindZhangzhishi>> list(AppFindZhangzhishiessayreq req){
        PageInfo<AppFindZhangzhishi> page = this.appFindZhangzhishiService.paginationQuery(req);
        return R.ok(page);
    }

    //    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "新增")
    @PostMapping(value = "/add")
    public R add(@RequestBody @Valid Zhangzhishiaddreq req) {
        boolean result = this.appFindZhangzhishiService.add(req);
        return super.isSuccess(result);
    }

    //    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "获取首页文章树")
    @GetMapping(value = "/home/data")
    public R<List<FindTreeResp>> homeFindTree() {
        List<FindTreeResp> tree = this.appFindZhangzhishiTitleService.homeFindTree();
        return R.ok(tree);
    }

    //    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据id查询文章")
    @GetMapping("/essay/{id}")
    public R<FindZhangzhishiresp> findById(@PathVariable(value = "id") Long id) {
        FindZhangzhishiresp resp = this.appFindZhangzhishiService.findById(id);
        return R.ok(resp);
    }

    //    @PreAuthorize("@ss.hasAppPermi()")
    @ApiOperation(value = "根据id删除文章")
    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable(value = "id") Long id) {
        boolean result = this.appFindZhangzhishiService.deleteById(id);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "修改")
    @PutMapping(value = "/edit")
    public R updateFindEssay(@RequestBody @Valid ZhangzhishiEssayEidtreq req) {
        boolean result = this.appFindZhangzhishiService.updateessay(req);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "获取文章分类")
    @GetMapping(value = "/title")
    public R<PageInfo<AppFindZhangzhishiTitle>> list(AppFIndZhangzhishititlereq req) {
        PageInfo<AppFindZhangzhishiTitle> page = this.appFindZhangzhishiTitleService.paginationQuery(req);
        return R.ok(page);
    }
}
